leader.time <- 1:10
model.leader.pop <- data.frame(matrix(NA,nrow=length(leader.time),ncol=3))
model.leader.p <- data.frame(matrix(NA,nrow=length(leader.time),ncol=3))



for(i in 1:10){

model.r.i.pop <- lm(legippop~ past.conference.number.noIR+ incidence_flag + mad_gdppc + p_polity2 + gwf_personal + gwf_party + gwf_military+leader.size+high_settlers.impute+decol_war+col_br.impute+col_fr.impute, data=epr.final[is.na(epr.final$inclprop)==FALSE & epr.final$first.leader==1 & epr.final$leader.time.in.office==i,])

model.leader.pop[i,1] <- leader.time[i]
model.leader.pop[i,2] <- summary(model.r.i.pop)$coefficients[2,1]
model.leader.pop[i,3] <- summary(model.r.i.pop)$coefficients[2,2]

model.r.i.p <- lm(inclprop~ past.conference.number.noIR+ incidence_flag + mad_gdppc + p_polity2 + gwf_personal + gwf_party + gwf_military+leader.size+high_settlers.impute+decol_war+col_br.impute+col_fr.impute, data=epr.final[is.na(epr.final$inclprop)==FALSE & epr.final$first.leader==1 & epr.final$leader.time.in.office==i,])

model.leader.p[i,1] <- leader.time[i]
model.leader.p[i,2] <- summary(model.r.i.p)$coefficients[2,1]
model.leader.p[i,3] <- summary(model.r.i.p)$coefficients[2,2]

}


names(model.leader.pop) <- c("year","estimate","se")
names(model.leader.p) <- c("year","estimate","se")

setwd(pathOUT)
p <- ggplot(model.leader.p, aes(x=year, y=estimate, ymin = estimate - 1.96*se, ymax = estimate + 1.96*se)) +
		ylim(-0.5,0.5)+
		geom_pointrange()+
			labs(title = "",
             x = "First Leader Year",
             y = "Estimate")+ theme_bw() + geom_hline(yintercept=0,linetype="dashed")
             
             ggsave("leader_p.pdf",p,width = 15, height = 10*1.63, units = c("cm"))

p <- ggplot(model.leader.pop, aes(x=year, y=estimate, ymin = estimate - 1.96*se, ymax = estimate + 1.96*se)) +
		ylim(-0.5,0.5)+
		geom_pointrange()+
			labs(title = "",
             x = "First Leader Year",
             y = "Estimate")+ theme_bw() + geom_hline(yintercept=0,linetype="dashed")
             
             ggsave("leader_pop.pdf",p,width = 15, height = 10*1.63, units = c("cm"))

